package com.smec.remes.module.submit.activity;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;

import com.hwangjr.rxbus.annotation.Subscribe;
import com.hwangjr.rxbus.annotation.Tag;
import com.hwangjr.rxbus.thread.EventThread;
import com.smec.moblie.R;
import com.smec.moblie.databinding.ActivityShouhuoBinding;
import com.smec.remes.base.SmecBaseActivity;
import com.smec.remes.bean.SubmitDetails;
import com.smec.remes.module.submit.SmecSubmitPresenter;
import com.smec.remes.module.submit.adapter.SmecShouChildrenAdapter;
import com.smec.remes.util.CommonUtils;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/22.
 */

public class SubmitShouHuoActivity extends SmecBaseActivity<SmecSubmitPresenter> {

    private ActivityShouhuoBinding activityShouhuoBinding;
    private SmecShouChildrenAdapter smecShouChildrenAdapter;
    public static final String SHOUHUO="SHOUHUO";
    public static final String SHOUHUOFAIL="SHOUHUOFAIL";
    private String applyOrderNo="";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityShouhuoBinding=DataBindingUtil.setContentView(this, R.layout.activity_shouhuo);
        smecShouChildrenAdapter=new SmecShouChildrenAdapter(this);
        activityShouhuoBinding.shouhuoRecyclerView.setLayoutManager(new LinearLayoutManager(SubmitShouHuoActivity.this));
        activityShouhuoBinding.shouhuoRecyclerView.setAdapter(smecShouChildrenAdapter);
        _getIntent();
        _return();
    }

    public void _getIntent(){
        Intent intent=getIntent();
        applyOrderNo=intent.getStringExtra("applyOrderNo");
        mPresenter._shouhuoDetails(applyOrderNo);
    }
    public void _return(){
        activityShouhuoBinding.searchTopbar.getTvTextLeft().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
                mRxBus.post("Refresh","true");
            }
        });
    }

    @Subscribe(
            thread = EventThread.MAIN_THREAD,
            tags = {
                    @Tag(SHOUHUO)
            }
    )

    public void _detailsSuccess(ArrayList<SubmitDetails> arrayList){
        if(CommonUtils.notEmpty(arrayList)){
            if(CommonUtils.notEmpty(arrayList.get(0).getConfirmedList())){
                smecShouChildrenAdapter.setArrayList(arrayList.get(0).getConfirmedList());
            }
        }
    }

    @Subscribe(
            thread = EventThread.MAIN_THREAD,
            tags = {
                    @Tag(SHOUHUOFAIL)
            }
    )

    public void _detailsFail(String a){

    }

    @Override
    public SmecSubmitPresenter getPresenter() {
        return new SmecSubmitPresenter(this);
    }
}
